物件參考觀念 小試身手


Posted by hoyi-23 on 2021-06-22

var a = {x:1};
var b = a;
a.y = a = {x:2};

console.log(a.y);
console.log(b);

這邊要注意的是:

  1. a = {x:2} 是一種運算式
  2. a.y = a = {x:2} 是同步執行
  3. a.y 找的是原本的路徑

結果:

console.log(a.y); // undefined
console.log(b); 
// {x:1;
    y:{
        x:2;
        }
    };


#物件參考







Related Posts

practice Recursive Inheritance.c

practice Recursive Inheritance.c

React-[useEffect篇]- 如何選擇一個項目並且切換畫面

React-[useEffect篇]- 如何選擇一個項目並且切換畫面

〈 AI 學習筆記 〉Automated Machine Learning 簡介與Auto-Sklearn實作紀錄

〈 AI 學習筆記 〉Automated Machine Learning 簡介與Auto-Sklearn實作紀錄


Comments